<template>
	<view class="page">
		<view class="main">
			<view class="goods-wrap">
				<view class="goods-left">
					<view class="goods" v-for="(item,x) in oddGroup" :key="x" @click="toDetail(item)">
						<image class="goods-img" mode="aspectFill" :src="fileServer+item.productImg"></image>
						<view class="name">
							{{item.productName}}
						</view>
						<view class="price">
							<view class="text">
								<view class="red">
									{{item.mll}}
								</view>
								<view class="t">
									毛利
								</view>
							</view>
							<view class="text">
								<view class="t">
									零售
								</view>
								<view class="red">
									{{item.price}}
								</view>
							</view>
							<view class="text">
								<view class="t">
									产地{{item.chandi}}
								</view>
							</view>
						</view>
					</view>
				</view>
				<view class="goods-rit">
					<view class="goods" v-for="item in evenGroup">
						<image class="goods-img"  mode="aspectFill" :src="fileServer+item.productImg"></image>
						<view class="name">
							{{item.productName}}
						</view>
						<view class="price">
							<view class="text">
								<view class="red">
									{{item.mll}}
								</view>
								<view class="t">
									毛利
								</view>
							</view>
							<view class="text">
								<view class="t">
									零售
								</view>
								<view class="red">
									{{item.price}}
								</view>
							</view>
							<view class="text">
								<view class="t">
									产地{{item.chandi}}
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<u-empty v-if="status!='loading'&&lists.length==0"
		        mode="data"
		        icon="http://cdn.uviewui.com/uview/empty/list.png"
		>
		</u-empty>
		<u-loadmore :status="status" v-else />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				fileServer: this.$fileServer,
				lists: [],
				status:'loading',//loading / nomore
				pageIndex:1,
				total:0,
				oddGroup: [],
				evenGroup: [],
				type:'',//9.9促销 1; 大牌专区 2
			};
		},
		onLoad(e) {
			this.type = e.type;
			this.getList()
		},
		methods: {
			
			getList() {
				let pageIndex = this.pageIndex;
				this.status = 'loading';
				if(this.type==1){
					this.$api.company.get99ZqList({pageIndex}).then(res => {
						uni.stopPullDownRefresh(); // 关闭下拉刷新 
						if (res.code==200) {
							this.lists = this.lists.concat(res.rows)
							let list = JSON.parse(JSON.stringify(this.lists))
							const oddGroup = list.filter((x, index) => index % 2 !== 0);
							const evenGroup = list.filter((x, index) => index % 2 === 0);
							this.oddGroup = oddGroup||[];
							this.evenGroup = evenGroup||[];
							this.total = res.total;
							
							if(this.lists.length<res.total){
								this.status = 'loadmore';
							}else{
								this.status = 'nomore';
							}
						}
						
					})
				}else{
					this.$api.company.getDpzqList({pageIndex}).then(res => {
						uni.stopPullDownRefresh(); // 关闭下拉刷新 
						if (res.code==200) {
							this.lists = this.lists.concat(res.rows)
							let list = JSON.parse(JSON.stringify(this.lists))
							const oddGroup = list.filter((x, index) => index % 2 !== 0);
							const evenGroup = list.filter((x, index) => index % 2 === 0);
							this.oddGroup = oddGroup||[];
							this.evenGroup = evenGroup||[];
							if(this.lists.length<res.total){
								this.status = 'loadmore';
							}else{
								this.status = 'nomore';
							}
						}
					})
				}
				
			},
			toDetail(item) {
				console.log(item);
				let id = item.id;
				uni.navigateTo({
					url: "/pages/shop/detail/detail?id="+id
				})
			},
		},
		onPullDownRefresh () {
		  this.getList()
		},
	}
</script>

<style lang="scss" scoped>
	.page {
		background: linear-gradient(to bottom, #ffffff, #f5f5f5);min-height: 100vh;
		// .popupCont{position: relative;padding: 24rpx;width: 375rpx;box-sizing: border-box;height: 100%;
		// 	.tit{font-size: 30rpx;color: #333;font-weight: bold;margin-bottom: 30rpx;}
		// 	.btns{position: absolute;left: 24rpx;right: 24rpx;bottom: 24rpx;display: flex;justify-content: space-between;
		// 		.btn{width: 48%;}
		// 	}
		// }
		.main {
			padding: 20rpx 32rpx;
			width: 100%;

			.swiper-wrap {
				margin-top: 24rpx;
			}

			.classify-wrap {
				margin-top: 20rpx;
				width: 100%;
				background: #FFFFFF;
				border-radius: 18rpx;
				padding: 20rpx 20rpx 0 18rpx;
				overflow: hidden;

				.item {
					width: 114rpx;
					margin-right: 18rpx;
					margin-bottom: 14rpx;
					float: left;

					.icon {
						width: 114rpx;
						height: 114rpx;
						margin-bottom: 8rpx;
					}

					.label {
						font-size: 28rpx;
						text-align: center;
					}

					&:nth-child(5n) {
						margin-right: 0;
					}
				}
			}

			.classify-type {
				margin-top: 24rpx;

				.item {
					width: auto;
					height: 56rpx;
					background: #EBEBEB;
					border-radius: 28rpx;
					padding: 0 12rpx;
					display: inline-block;
					margin-right: 20rpx;
					font-size: 28rpx;
					white-space: nowrap;
					line-height: 56rpx;

					&.active {
						background: #EC2424;
						color: #fff;
					}
				}
			}

			.adv-wrap {
				width: 100%;
				display: flex;
				align-items: center;
				justify-content: space-between;
				.advItem{position: relative;width: 216rpx;height: 160rpx;
					.text{position: absolute;top: 0;left: 0;padding: 16rpx;
						.h{color: #333333;font-size: 32rpx;font-weight: bold;margin-bottom: 10rpx;}
						.p{color: #333333;font-size: 24rpx;}
					}
				}
				.adv {
					width: 216rpx;
					height: 160rpx;
					border-radius: 16rpx;
				}
			}

			.select-type {
				width: 100%;
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin-top: 24rpx;
				position: relative;

				.select {
					display: flex;
					align-items: center;
					.text {
						max-width: 150rpx;
						color: #333;
						font-size: 32rpx;margin-right: 5rpx;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;
					}

					.icon {
						width: 22rpx;
						height: auto;
					}
				}
				.selectCont{position: absolute;left: 0;top: 45rpx;right: 0;background: #fff;padding: 24rpx;box-shadow: 0 5 50rpx #999;
					.selectform{display: flex;align-items: center;}
					.btns{display: flex;align-items: center;justify-content: space-between;margin-top: 30rpx;
						.btn{width: 48%;}
					}
				}
			}

			.goods-wrap {
				width: 100%;
				display: flex;
				margin-top: 24rpx;

				.goods-left,
				.goods-rit {
					width: 334rpx;
				}

				.goods-left {
					margin-right: 16rpx;
				}

				.goods-pic {
					width: 100%;
					overflow: hidden;
					margin-bottom: 8rpx;

					.pic {
						width: 160rpx;
						height: 160rpx;
						border-radius: 16rpx;
						margin-right: 14rpx;
						margin-bottom: 16rpx;

						&:nth-child(2n+0) {
							margin-right: 0;
						}
					}
				}

				.goods {
					margin-bottom: 24rpx;
					width: 100%;
					background: #FFFFFF;
					border-radius: 16rpx;
					overflow: hidden;
					padding-bottom: 20rpx;

					.goods-img {
						width: 100%;
						height: 334rpx;
					}

					.name {
						margin-top: 16rpx;
						font-size: 28rpx;
						line-height: 40rpx;
						padding: 0 12rpx;
					}

					.price {
						display: flex;
						align-items: center;
						justify-content: space-between;
						padding: 0 12rpx;
						margin-top: 10rpx;

						.text {
							display: flex;
							align-items: center;

							.red {

								color: #E83149;
								font-size: 28rpx;
							}

							.t {

								font-size: 22rpx;
							}
						}
					}

				}
			}
		}
	}
</style>